import jwt
import datetime
#载荷中加入生命周期的概念
playload={
    # 过期时间
    'exp':int((datetime.datetime.now()+datetime.timedelta(seconds=60)).timestamp()),
    'data':{'uid':'2'}

}

# 生成jwt
encode_jwt=jwt.encode(playload,'201528',algorithm='HS256')
# 转码
encode_str=str(encode_jwt,'utf-8')

print(encode_str)

# 解密
try:
    decode_jwt=jwt.decode(encode_str,'201528',algorithms=['HS256'])
    print(decode_jwt)
except Exception as e:
    print('已过期')

